package com.dozen.share;

import com.dozen.commonbase.utils.MyLog;
import com.dozen.commonbase.utils.TimeUtil;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Dozen
 * @description:
 * @time: 2022/3/28
 */
public class ShareConstant {

    public static List<UrlBean> loadShareUrl() {
        List<UrlBean> list = new ArrayList<>();

        list.add(new UrlBean(ShareType.share_type_xiuqiu, "雪球", "https://xueqiu.com/hq", "tableContent", 3, true));
        list.add(new UrlBean(ShareType.share_type_tonghuaxun, "同花顺", "http://stock.10jqka.com.cn/", "ui-table-ss", 0, true));
        list.add(new UrlBean(ShareType.share_type_taoguoba, "淘股吧", "https://www.taoguba.com.cn/stock/moreHotStock", "hot_hsnr_l", 0, true));
        list.add(new UrlBean(ShareType.share_type_xinlan, "新浪", "https://guba.sina.com.cn/?s=bar&name=sh000001", "table_01", 0, true));
        list.add(new UrlBean(ShareType.share_type_dongfancaifu, "东方", "http://guba.eastmoney.com/", "list", 0, true));

        return list;
    }

    public static List<ShareBean> shareBeanData;

    public static void addShare(ShareBean shareBean) {

        boolean sh = true;

        for (int i = 0; i < shareBeanData.size(); i++) {
            if (shareBean.getName().equals(shareBeanData.get(i).getName())) {
                shareBeanData.get(i).setNumber(shareBeanData.get(i).getNumber() + 1);
                shareBean.setNumber(shareBeanData.get(i).getNumber());
                sh = false;
            }
        }

        if (sh) {
            shareBeanData.add(shareBean);
        } else {
            if (shareBean.getNumber() == 5) {
                String time = TimeUtil.getCurrentDataThree();
                int timeInt = Integer.parseInt(time);
                MyLog.d("111111111111112222222222:" + time);

//                timeInt = 18;

                if (timeInt < 9 || timeInt > 17) {
                    List<ShareBean> list = DataSupport.where("times = \"" + shareBean.getTimes() + "\"").find(ShareBean.class);
                    boolean save = true;
                    for (int l = 0; l < list.size(); l++) {
                        MyLog.d("111111111111112222222222:" + list.get(l).getName());
                        if (list.get(l).getName().equals(shareBean.getName())) {
                            save = false;
                        }
                    }

                    if (save) {
                        shareBean.save();
                    }
                }
            }
        }

    }


}
